<?php

function parse_platform( $batch, $platform ) {
    $context = getContext(true,$platform->proxy);

    $url = 'http://www.symbid.com/ideas?q%5Bsearch%5D=';
    $html = file_get_html($url, false, $context);
    
    $articles = $html->find('div[class="info-block"]');
    
    foreach($articles as $article) {
        
        $href = $article->find('a',0)->href;
        
        $image = $article->find('img',0)->src;
        $link = "https://www.symbid.com" . $href;
        $name = str_replace('\'','',$article->find('h3',0)->find('a',0)->plaintext);
        $description = $article->find('p',0)->plaintext;
        $external_id = substr($href,strrpos($href,'/')+1,strpos($href,'-')-strrpos($href,'/')-1);
        $currency = '$';
        
        foreach ($article->find('td[class!=cell3]') as $td){ 
            $value = $td->find('strong',0)->plaintext;
            switch ($td->find('span',0)->plaintext) {
                case 'Days':
                $days = $value;
                break;
                case 'INVESTED':
                $current = str_replace(',','',str_replace($currency,'',$value));
                break;
                case 'required':
                $target = str_replace(',','',str_replace($currency,'',$value));
                break;
                case 'equity':
                $shares = str_replace('%','',$value);
                break;
            }
        }
        $td = $article->find('td[class=cell]',0);
        if($td){
            $worth = str_replace(',','',str_replace(' ','',str_replace($currency,'',$td->find('strong',-1)->plaintext)));
            if(strpos($worth,'M') != false) {
                $worth = str_replace('M','',$worth) * 1000000;
            }
        }
        $active = $days > 0 ? 1 : 0;
        
        if($batch) {
            saveProjectData($external_id, $platform, $batch, $current, $days, $worth, $shares, $target, $image, $link, $name, $description, $active, $currency);
        }
    }
}
?>